<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单位对账单')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
								<label>报表类型：</label>
								<select name="params[zbh]" id="zbh">
									<option th:each="bb:${dzdlist}" th:text="${bb.zbmc}" th:value="${bb.zbh}"></option>
								</select>
							</li>
                              <li class="select-time">
                                <label>查询日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endDate]"/>
                            </li>
							<li>
								<label>单位：</label>
								<select name="params[dwbm]" id="dwbm">
								</select>
							</li>
							<li style="width:265px">
                                <label>起始单位：</label> 
	                                 <div class="input-group">
		                                <input class="form-control" type="text" ondblclick="selectsHsdwTree()" id="sdwbm"  name="params[sdwbm]">
		                        		<span class="input-group-addon"><i class="fa fa-search" onclick="selectsHsdwTree()"></i></span>
	                        		 </div> 
                            </li>
                            <li style="width:265px">
                                <label>终止单位：</label> 
	                                 <div class="input-group">
		                                <input class="form-control" type="text" ondblclick="selecteHsdwTree()" id="edwbm"  name="params[edwbm]">
		                        		<span class="input-group-addon"><i class="fa fa-search" onclick="selecteHsdwTree()"></i></span>
	                        		 </div> 
                            </li>
							 <li>
                                <label>显示无发生额单位：</label>
                                <input type="checkbox" name="params[flag]" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="listdwcxdy()"><i class="fa fa-edit"></i>&nbsp;定义</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
               
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:dwdzd:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/dwdzd";

        $(function() {
            var options = {
                url: prefix + "/list",
                exportUrl: prefix + "/export",
                modalName: "单位对账单",
                pagination: false,
                firstLoad: false,
                responseHandler: responseHandler,
                columns: [	
	                {
	                    field: 'nd',
	                    title: '记账年',
	                },{
	                    field: 'yf',
	                    title: '记账月',
	                },{
	                    field: 'rq',
	                    title: '记账日',
	                },{
	                    field: 'pzbh',
	                    title: '凭证号',
	                }, 
	                {
	                    field: 'zy',
	                    title: '摘要'
	                },
	                {
	                    field: 'jjyskmmc',
	                    title: '缴款人'
	                },
	                {
	                    field: 'yskm',
	                    title: '项目'
	                },
	                {
	                    field: 'yskmmc',
	                    title: '项目名称'
	                },{
	                    field: 'jfje',
	                    title: '借方金额',
	                },{
	                    field: 'dfje',
	                    title: '贷方金额',
	                },
	                {
	                    field: 'qmye',
	                    title: '余额'
	                }]
            };
            $.table.init(options);
        });
        
        /*核算单位-新增-选择父部门树*/
        function selectsHsdwTree() {
            var options = {
                title: '核算单位选择',
                width: "380",
                url: ctx + "system/hsdw/selectHsdwTree/",
                callBack: sdohsdwSubmit
            };
            $.modal.openOptions(options);
        }

        function sdohsdwSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#sdwbm").val(body.find('#treeId').val());
               layer.close(index);
        }
        /*核算单位-新增-选择父部门树*/
        function selecteHsdwTree() {
            var options = {
                title: '核算单位选择',
                width: "380",
                url: ctx + "system/hsdw/selectHsdwTree/",
                callBack: edohsdwSubmit
            };
            $.modal.openOptions(options);
        }

        function edohsdwSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#edwbm").val(body.find('#treeId').val());
               layer.close(index);
        }
        function query() {
        	
        	var startTime=$("#startTime").val();
        	var endTime=$("#endTime").val();
        	var sdwbm=$("#sdwbm").val();
        	var edwbm=$("#edwbm").val();
        	debugger;
        	if (startTime==''||endTime==''){
        		$.modal.alertWarning("查询起止时间不能为空");
        		return false;
        	}
        	if (startTime.substring(0,4)!=endTime.substring(0,4)){
        		$.modal.alertWarning("查询起止时间不能跨年");
        		return false;
        	}
        	if (sdwbm==''||edwbm==''){
        		$.modal.alertWarning("查询起止单位不能为空");
        		return false;
        	}
        	$.table.search();
        }
    	$("#dwbm").change(function(){
    		$.table.search();
		});
    	function responseHandler(res){
    		var areaList = res.subrows;
    		if (res.code==0 && areaList!=undefined){
    			if ($("#dwbm")[0].options.length!=areaList.length){
		    		$("#dwbm").empty(); 
					for(var i=0;i<areaList.length;i++){
						//这里两个方法是首先转化为json字符串，然后转化为json对象
						var json = JSON.stringify(areaList[i]);
						var area = JSON.parse(json);
						var str = "<option value="+area['dwbm']+">"+area['dwbm']+"-"+area['dwmc']+"</option>";             
						$("#dwbm").append(str);
					}
					$("#dwbm").trigger("liszt:updated");
					$("#dwbm").trigger("chosen:updated");
    			}
    		}
        }
   	 function listdwcxdy() {
		    var url = ctx + 'system/dwcxdy';
		    $.modal.openFull("单位查询定义", url, '800', '540');
		}
    </script>
</body>
</html>